import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToMany,
  JoinTable,
} from 'typeorm';
import { SysUser } from '../../sys-user/entities/sys-user.entity';
import { SysMenu } from '../../sys-menu/entities/sys-menu.entity';

@Entity('sys_role')
export class SysRole {
  @PrimaryGeneratedColumn({ comment: '角色ID' })
  role_id: number;

  @Column({ nullable: true, comment: '角色名称' })
  role_name: string;

  @Column({ nullable: true, comment: '角色权限字符串' })
  role_key: string;

  @Column({ nullable: true, comment: '显示顺序' })
  role_sort: number;

  @Column({
    default: '1',
    comment:
      '数据范围（1：全部数据权限 2：自定数据权限 3：本部门数据权限 4：本部门及以下数据权限）',
  })
  data_scope: string;

  @Column({ default: 1, comment: '菜单树选择项是否关联显示' })
  menu_check_strictly: number;

  @Column({ default: 1, comment: '部门树选择项是否关联显示' })
  dept_check_strictly: number;

  @Column({ nullable: true, comment: '角色状态（0正常 1停用）' })
  status: string;

  @Column({ default: '0', comment: '删除标志（0代表存在 2代表删除）' })
  del_flag: string;

  @Column({ default: '', comment: '创建者' })
  create_by: string;

  @Column({ type: 'datetime', comment: '创建时间' })
  create_time: Date;

  @Column({ default: '', comment: '更新者' })
  update_by: string;

  @Column({ type: 'datetime', comment: '更新时间' })
  update_time: Date;

  @Column({ comment: '备注' })
  remark: string;

  @ManyToMany(() => SysUser, (user) => user.roles)
  @JoinTable({
    name: 'sys_user_role',
    joinColumn: {
      name: 'role_id',
      referencedColumnName: 'role_id',
    },
    inverseJoinColumn: {
      name: 'user_id',
      referencedColumnName: 'user_id',
    },
  })
  users: SysUser[];

  @ManyToMany(() => SysMenu, (menu) => menu.roles)
  menus: SysMenu[];
}
